package service

import (
	"gitee.com/failurejack/smart-construction/global"
	"gitee.com/failurejack/smart-construction/model"
)

type UserService struct{}

var UserServiceApp = new(UserService)

func (u *UserService) CreateUser(mu model.User) (err error) {
	err = global.DB.Create(&mu).Error
	return err
}

func (u *UserService) DeleteUser(mu model.User) (err error) {
	err = global.DB.Delete(&mu).Error
	return err
}

func (u *UserService) UpdateUser(mu *model.User) (err error) {
	err = global.DB.Save(mu).Error
	return err
}

func (u *UserService) GetUser(id uint) (mu model.User, err error) {
	err = global.DB.Where("id = ?", id).First(&mu).Error
	return
}

func (u *UserService) GetUserList() (list interface{}, total int64, err error) {
	db := global.DB.Model(&model.User{})
	var userList []model.User
	//pageNumber := 1
	//pageSize := 10
	err = db.Unscoped().Find(&userList).Error
	//err = db.Count(&total).Offset((pageNumber - 1) * pageSize).Limit(pageSize).Find(&userList).Error
	return userList, int64(len(userList)), err
}
